home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot.new / h / clock.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-19  |  4.6 KB  |  122 lines

  1.  
  2. /*    @(#)clock.h 1.1 86/09/27 SMI    */
  3.  
  4. /*
  5.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  6.  */
  7.  
  8. /*
  9.  * Definitions for the Intersil 7170 real-time clock.  This chip
  10.  * is used as the timer chip in addition to being the battery
  11.  * backed up time-of-day device.  This clock is run by UNIX in
  12.  * the 100 hz periodic mode giving interrupts 100 times/second.
  13.  * The low level code dismisses every other interrupt, thus
  14.  * creating an effective 50 hz rate for hardclock().
  15.  *
  16.  * Reading clk_hsec latches the the time in all the other bytes
  17.  * so you get a consistent value.  To see any byte change, you
  18.  * have to read clk_hsec in between (e.g. you can't loop waiting
  19.  * for clk_sec to reach a certain value without reading clk_hsec
  20.  * each time).
  21.  */
  22.  
  23. #define    SECDAY    ((unsigned)(24*60*60))        /* seconds per day */
  24. #define    SECYR    ((unsigned)(365*SECDAY))    /* seconds per common year */
  25. #define    SECYEAR(yr)    ((((unsigned)(yr) % 4) == 0)? SECYR + SECDAY : SECYR)
  26.  
  27. /*
  28.  * The year register counts from 0 to 99.
  29.  * Unix time is the number of seconds
  30.  * since the year YRREF.  The 2 digit year
  31.  * value stored in the chip represents the 
  32.  * the number of years beyond YRBASE.
  33.  * Note that YRBASE must be < YRREF and
  34.  * (YRBASE % 4) == 0 to do leap years correct.
  35.  * Note that we can only keep time up to the year 2068.
  36.  */
  37. #define    YRREF        70    /* 1970 - where UNIX time begins */
  38. #define    YRBASE        68    /* 1968 - what year 0 in chip represents */
  39.  
  40. #define    OBIO_CLKADDR    0x60000    /* address of clock in obio space */
  41.  
  42. struct intersil7170 {
  43.     u_char    clk_hsec;    /* counter - hundredths of seconds 0-99 */
  44.     u_char    clk_hour;    /* counter - hours 0-23 (24hr) 1-12 (12hr) */
  45.     u_char    clk_min;    /* counter - minutes 0-59 */
  46.     u_char    clk_sec;    /* counter - seconds 0-59 */
  47.     u_char    clk_mon;    /* counter - month 1-12 */
  48.     u_char    clk_day;    /* counter - day 1-31 */
  49.     u_char    clk_year;    /* counter - year 0-99 */
  50.     u_char    clk_weekday;    /* counter - week day 0-6 */
  51.     u_char    clk_rhsec;    /* RAM - hundredths of seconds 0-99 */
  52.     u_char    clk_rhour;    /* RAM - hours 0-23 (24hr) 1-12 (12hr) */
  53.     u_char    clk_rmin;    /* RAM - minutes 0-59 */
  54.     u_char    clk_rsec;    /* RAM - seconds 0-59 */
  55.     u_char    clk_rmon;    /* RAM - month 1-12 */
  56.     u_char    clk_rday;    /* RAM - day 1-31 */
  57.     u_char    clk_ryear;    /* RAM - year 0-99 */
  58.     u_char    clk_rweekday;    /* RAM - week day 0-6 */
  59.     u_char    clk_intrreg;    /* interrupt status and mask register */
  60.     u_char    clk_cmd;    /* command register */
  61.     u_char    clk_unused[14];
  62. };
  63. #define    CLKADDR ((struct intersil7170 *)(0x0FFE2000))
  64.  
  65. /* offsets into structure */
  66. #define    CLK_HSEC    0
  67. #define    CLK_HOUR    1
  68. #define    CLK_MIN        2
  69. #define    CLK_SEC        3
  70. #define    CLK_MON        4
  71. #define    CLK_DAY        5
  72. #define    CLK_YEAR    6
  73. #define    CLK_WEEKDAY    7
  74. #define    CLK_RHSEC    8
  75. #define    CLK_RHOUR    9
  76. #define    CLK_RMIN    10
  77. #define    CLK_RSEC    11
  78. #define    CLK_RMON    12
  79. #define    CLK_RDAY    13
  80. #define    CLK_RYEAR    14
  81. #define    CLK_RWEEKDAY    15
  82. #define    CLK_INTRREG    16
  83. #define    CLK_CMD        17
  84.  
  85. /*
  86.  * In `alarm' mode the 7170 interrupts when the current
  87.  * counter matches the RAM values.  However, if the ignore
  88.  * bit is on in the RAM counter, that register is not
  89.  * used in the comparision.  Unfortunately, the clk_rhour
  90.  * register uses a different mask bit (because of 12 hour
  91.  * mode) and thus the 2 different defines.
  92.  */
  93. #define    CLK_IGNORE    0x80    /* rmsec, rmin, rsec, rmon, rday, ryear, rdow */
  94. #define    CLK_HOUR_IGNORE    0x40    /* ignore bit for clk_rhour only */
  95.  
  96. /*
  97.  * Interrupt status and mask register defines,
  98.  * reading this register tells what caused an interrupt
  99.  * and then clears the state.  These can occur
  100.  * concurrently including te RAM compare interrupts.
  101.  */
  102. #define    CLK_INT_INTR    0x80    /* r/o pending interrrupt */
  103. #define    CLK_INT_DAY    0x40    /* r/w periodic day interrupt */
  104. #define    CLK_INT_HOUR    0x20    /* r/w periodic hour interrupt */
  105. #define    CLK_INT_MIN    0x10    /* r/w periodic minute interrupt */
  106. #define    CLK_INT_SEC    0x08    /* r/w periodic second interrupt */
  107. #define    CLK_INT_TSEC    0x04    /* r/w periodic 1/10 second interrupt */
  108. #define    CLK_INT_HSEC    0x02    /* r/w periodic 1/100 second interrupt */
  109. #define    CLK_INT_ALARM    0x01    /* r/w alarm mode - interrupt on time match */
  110.  
  111. /* Command register defines */
  112. #define    CLK_CMD_TEST    0x20    /* w/o test mode (vs. normal mode) */
  113. #define    CLK_CMD_INTRENA    0x10    /* w/o interrupt enable (vs. disabled) */
  114. #define    CLK_CMD_RUN    0x08    /* w/o run bit (vs. stop) */
  115. #define    CLK_CMD_24FMT    0x04    /* w/o 24 hour format (vs. 12 hour format) */
  116. #define    CLK_CMD_F4M    0x03    /* w/o using 4.194304MHz crystal frequency */
  117. #define    CLK_CMD_F2M    0x02    /* w/o using 2.097152MHz crystal frequency */
  118. #define    CLK_CMD_F1M    0x01    /* w/o using 1.048576MHz crystal frequency */
  119. #define    CLK_CMD_F32K    0x00    /* w/o using  32.768KHz  crystal frequency */
  120.  
  121. #define    CLK_CMD_NORMAL    (CLK_CMD_INTRENA|CLK_CMD_RUN|CLK_CMD_24FMT|CLK_CMD_F32K)
  122.